formContainer.onsubmit = function (e) {
    e.preventDefault();
    var loginId = userName.value.trim();
    var loginPwd = userPassword.value.trim();
    // 表单数据发送处理
    if (!loginId || !loginPwd) {
        alert("用户名或密码不能为空");
        return;
    }
    // 获取后端的token值

    var sendData = async function (loginId, loginPwd) {
        var res = await fetch("https://study.duyiedu.com/api/user/login", {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
            },
            body: JSON.stringify({
                loginId,
                loginPwd
            })
        })
        var token = res.headers.get("Authorization");
        // 存储token值,前面token有值就执行后面的代码
        token && (sessionStorage.token = token)
        sessionStorage.token && (sessionStorage.Authorization = 'Bearer'+ " " + sessionStorage.token)

        var result = await res.json();
        if (result.code !== 0) {
            alert(result.msg);
            return;
        }
        // 成功就发生跳转
        location.href = `./robot/robot.html`;
    }
    sendData(loginId, loginPwd);
}

